package br.usp.ime.mac.mico.models;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.ManyToOne;

import br.usp.ime.mac.mico.models.Box;


@Embeddable
public class Place {

	//Place's attributes.
	//NOTE: possibly we could make it a flyweight.
	@Column(name="index_x", nullable = false)
	private long indexX;

	@Column(name="index_y", nullable = false)
	private long indexY;

    @ManyToOne
	private Box box;

	public Place(long indexX, long indexY, Box box) {
		this.indexX = indexX;
		this.indexY = indexY;
		this.box    = box;
	}

	public Box getBox() {
		return box;
	}

	public void setBox(Box box) {
		this.box = box;
	}

	public long getIndexX() {
		return indexX;
	}

	public void setIndexX(long indexX) {
		this.indexX = indexX;
	}

	public long getIndexY() {
		return indexY;
	}

	public void setIndexY(long indexY) {
		this.indexY = indexY;
	}

	@Override
	public boolean equals(Object comparedObject) {
		if(comparedObject == null ||
				!comparedObject.getClass().equals(this.getClass()))
			return false;
		Place comparedPlace = (Place) comparedObject;
		if(this.getBox().equals(comparedPlace.getBox()) &&
			this.getIndexX() == comparedPlace.getIndexX() &&
			this.getIndexY() == comparedPlace.getIndexY())
			return true;
		return false;
	}
}
